from flask import Blueprint,jsonify,request,abort
from flask_restful import Api,Resource
from app.models import *
school_income0 = Api()

class School_Income1(Resource):
    def get(self):
        select = School_Income.query.all()
        return jsonify({"select": list(map(con5, select))})
    def post(self, uid):
        selec = School_Income(
            request.json["time"],
            request.json["study_textual_research_name"],
            request.json["phone"],
            request.json["wechat"],
            request.json["all_in_cost"],
            request.json["real_pay"],
            request.json["not_pay"],
            request.json["discounts"],
            request.json["travelling_expenses"],
            request.json["Payment_of_fees"],
            request.json["Paymeng_method"],
            request.json["Internal_business"],
            request.json["source"],
            request.json["remarks"]
        )
        db.session.add(selec)
        db.session.commit()
        return jsonify({"selec": con5(selec)}), 201
school_income0.add_resource(School_Income1, "/School_Income1/")


class School_Income2(Resource):
    def get(self, uid):
        selec = School_Income.query.filter_by(id=uid).first()
        if selec is None:
            abort(404)
        return jsonify({"selec": con5(selec)})

    def put(self, uid):
        selec = School_Income.query.get(uid)
        selec.time = request.json.get("time")
        selec.study_textual_research_name = request.json.get("study_textual_research_name")
        selec.phone = request.json.get("phone")
        selec.wechat = request.json.get("wechat")
        selec.all_in_cost = request.json.get("all_in_cost")
        selec.real_pay = request.json.get("real_pay")
        selec.not_pay = request.json.get("not_pay")
        selec.discounts = request.json.get("discounts")
        selec.travelling_expenses = request.json.get("travelling_expenses")
        selec.Payment_of_fees = request.json.get("payment_of_fees")
        selec.Paymeng_method = request.json.get("Paymeng_method")
        selec.Internal_business = request.json.get("Internal_business")
        selec.source = request.json.get("source")
        selec.remarks = request.json.get("remarks")
        db.session.add(selec)
        db.session.commit()
        return jsonify({"selec": con5(selec)})


school_income0.add_resource(School_Income2, "/School_Income2/<int:uid>/")